package org.example.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.utils.ChineseStringGeneratorUtils;
import org.example.utils.TranslationUtils;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName("project_version_detail")
public class ProjectVersionDetail extends BaseEntity{


    private String localism;

    private String scene;

    private Long versionId;


    @TableField(exist = false)
    private List<ProjectVersionTranslateDetail> translateDetails;

    public List<ProjectVersionTranslateDetail> form(){
        List<String> strings = ChineseStringGeneratorUtils.targetLanguage();
        return CollectionUtils.isEmpty(strings)
                ? null
                : strings.stream().map(language -> {
                    ProjectVersionTranslateDetail build = ProjectVersionTranslateDetail.builder().targetLanguage(language).translation(TranslationUtils.getTranslation()).build();
                    build.setCreateTime(LocalDateTime.now());
                    build.setUpdateTime(LocalDateTime.now());
                   return build;
                })
                .collect(Collectors.toList());
    }

}
